package com.webchat.client.payment.service;


import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.exception.BusinessException;
import com.webchat.common.util.IDGenerateUtil;
import com.webchat.domain.dto.payment.PaymentOrderDTO;
import com.webchat.domain.dto.payment.PaymentResultDTO;
import com.webchat.domain.dto.payment.PaymentTransferRequestDTO;
import com.webchat.rmi.pay.PaymentApiServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PaymentOrderService {


    @Autowired
    private PaymentApiServiceClient paymentApiServiceClient;


    /**
     * 获取支付订单详情
     *
     * @param orderId
     * @param accessToken
     * @return
     */
    public PaymentOrderDTO orderInfo(String orderId, String userId, String accessToken) {

        APIResponseBean<PaymentOrderDTO> responseBean = paymentApiServiceClient.orderInfo(orderId, userId, accessToken);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw  new BusinessException(responseBean.getMsg());
    }


    /**
     * 确认支付
     *
     * @param paymentTransferRequest
     * @param accessToken
     * @return
     */
    public PaymentResultDTO transfer(PaymentTransferRequestDTO paymentTransferRequest,
                                     String accessToken) {

        String logId = IDGenerateUtil.uuid();
        APIResponseBean<PaymentResultDTO> responseBean = paymentApiServiceClient.transfer(paymentTransferRequest, accessToken, logId);
        if (APIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        throw new BusinessException(responseBean.getMsg());
    }

}
